package swarch.messageflow;

import javax.annotation.Resource;
import javax.jbi.messaging.DeliveryChannel;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
import javax.xml.transform.TransformerException;

import org.apache.log4j.Logger;
import org.apache.servicemix.components.util.ComponentSupport;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.listener.MessageExchangeListener;

public class MissionMessageBean extends ComponentSupport implements MessageExchangeListener {

	private final static Logger logger = Logger.getLogger(MissionMessageBean.class);
	private SourceTransformer sourceTransformer = new SourceTransformer();
	@Resource
	private DeliveryChannel channel;

    public void onMessageExchange(MessageExchange exchange) throws MessagingException {
    	NormalizedMessage inMessage = getInMessage(exchange);
        try {        	
        	
        	logger.info("Mission Enricher: Before Remove: " + sourceTransformer.toString(inMessage.getContent()));
        	// remove message content
//        	inMessage.setContent(new StringSource(""));
        	
//        	logger.info("Mission Enricher: " + sourceTransformer.toString(inMessage.getContent()));
        } catch(TransformerException e) {
        	logger.error("error while reading payload", e);
		}
//        NormalizedMessage outMessage = exchange.createMessage();
//        outMessage.setContent(new StringSource(""));
//        exchange.setMessage(outMessage, "out");
//        exchange.setStatus(ExchangeStatus.DONE);
        channel.send(exchange);
    }
}
